hi
how can i store level.a1, level.a2 , level.a3, level.a4 and level.a5 in the variable level.vr1
pseudocode : level.vr1 = level.a1 + level.a2 + level.a3 + level.a4 + level.a5
Boni
hi
how can i store level.a1, level.a2 , level.a3, level.a4 and level.a5 in the variable level.vr1
pseudocode : level.vr1 = level.a1 + level.a2 + level.a3 + level.a4 + level.a5
Boni
Hi
You could store the values in an array
So you would turn level.vr1 from a variable into an array
level.vr1[1] = level.a1
level.vr1[2] = level.a2
level.vr1[3] = level.a3
See http://gronnevik.se/rjukan/index.php...Language#toc10
Purple's Playground
OBJ : 103.29.85.127:12203
xfire: purpleelephant1au
email: purpleelephant1au@gmail.com
skydrive: PurpleElephantSkydrive
hey purple
Thanks for the reply
What i'm trying to achieve is to use level.vr1 for all the entities in the list like
level.vr1[1] = level.a1
level.vr1[2] = level.a2
level.vr1[3] = level.a3
level.vr1[4] = level.a4
level.vr1[5] = level.a5
level.vr1[6] = level.a6
if( self cansee level.vr1 ? ) <- what to write here to make self react if it sees level.a1 or level.a2 or level.a3 ...
By the way, what's with the ingame browser in MoHAA,
i thought it would stop working on May 31,
but it's still working fine !
You would still save all the entities into the array and just loop through each iteration in a for() loop and then add the cansee check
It will loop through each entity saved in the array until it reaches the end.Code:for (local.i = 1; local.i <= level.vr1.size; local.i++) { if(self cansee level.vr1[local.i]) { //do code } }
GameSpy Shutdown got postponed till end of this month so June 30th
See
http://www.x-null.net/forums/showthr...ssue-IMPORTANT
and
www.ea.com/1/service-updates
Purple's Playground
OBJ : 103.29.85.127:12203
xfire: purpleelephant1au
email: purpleelephant1au@gmail.com
skydrive: PurpleElephantSkydrive
yeah about for , all i read is it loops like while , but complix or something like dat , any good demonstration
Try Reading up on it on the link i posted on first reply
The for statement
The for statement is very similar to the while statement, but its declaration is more complex; making it easier to adapt to special cases:
At the start of execution of this entire statement, statement1 is executed. At the start of a cycle of the loop the expression expr is evaluated, and while the expression evaluates to true ( 1 ) the statement(s) within the "curly brackets" following the for clause are executed. At the end of each cycle of the loop, statement2 is executed.Code:for ( statement1 ; expr ; statement2 ) { statement ... statement }
So With my example for the level.vr1 array
It will first do the first statement which is local.i = 1,Code:for (local.i = 1; local.i <= level.vr1.size; local.i++) { if(self cansee level.vr1[local.i]) { //do code } }
It will then check whether the expressing it true(1) , which is local.i <= level.vr1.size, so its if local.i is equal or less then the size of the array, which is true(1)
If the expression is true , it executes what is inside the brackets, if false, it ends
At the end of the loop , it will do the second statement which is local.i++, which is the same as local.i + 1
It then starts the cycle again until the expression is false(0)
Notice inside the brackets it uses local.i , which changes at each iteration because of the second statement, local.i++ , thus it will cycle through the variables inside the array without needing to re-write each one out.
Last edited by Purple Elephant1au; June 17th, 2014 at 05:16 AM.
Purple's Playground
OBJ : 103.29.85.127:12203
xfire: purpleelephant1au
email: purpleelephant1au@gmail.com
skydrive: PurpleElephantSkydrive
Thats nice , thx
but is for always state 1 and expr and state 2 only ?
no more ? no less ?
OK, that worked like a charm
Thanks for the code Purple
hi RyBack, nice you joined this topic.
And for the sake of completeness,
here is the code
Code:issniper: level.vr1[1] = level.a1 level.vr1[2] = level.a2 level.vr1[3] = level.a3 level.vr1[4] = level.a4 level.vr1[5] = level.a5 level.vr1[6] = level.a6 for (local.i = 1; local.i <= level.vr1.size; local.i++) {wait 2 if( self cansee level.vr1[local.i] && "springfield '03 sniper" == level.vr1[local.i].gun || "mauser kar 98d sniper" == level.vr1[local.i].gun ) { $gp playsound gps4 } // sniper ! } end
An interesting thing to note is that for loops are essentially just glorified while loops. They really just do this:
Since iterating over arrays or collections of variables is such an integral part of programming, the for loop was born just for convenience's sake.Code:local.i = 1; while(local.i <= $player.size) { $player[local.i] kill; local.i++; }
Syntactic sugar as we programmers like to call it. Take the "local.i++", for instance. That's syntactic sugar for "local.i += 1" which in turn is
syntactic sugar for "local.i = local.i + 1".
Morpheus Script (MoH) => You try to shoot yourself in the foot only to discover that MorpheusScript already shot your foot for you.
I suggest you add parenthesis between the OR logical operator like below.
Because what you did in your code, it first checks if the player can see one of the vr, AND the vr has a springfield or SIMPLY the vr has a gun, this way is better :
Logical operators in C/C++ share the same priority (left to right).Code:if( self cansee level.vr1[local.i] && ( level.vr1[local.i].gun == "springfield '03 sniper" || level.vr1[local.i].gun == "mauser kar 98d sniper" ) )